﻿var dbModule = (function () {
    var mongoDB = new MongoLab('FlgTc4pFh1IVFPfxXF2q4qnfBWksx4Sw');

    var Get = Class.create({
        initialize: function () {
            this.count;
        },

        allOffers: function (result) {
            mongoDB.listDocuments('vozime_db', 'drivers', function (data) {
                result(data);
            });
        },

        offerByConditions: function (tripObj, result) {
            if ((tripObj.from != "0" && tripObj.to != "0") && (tripObj.from != undefined && tripObj.to != undefined)) {
                mongoDB.listDocuments('vozime_db', 'drivers', q = { trip: JSON.stringify(tripObj) }, function (data) {
                    result(data);
                });
            }
            else {
                mongoDB.listDocuments('vozime_db', 'drivers', function (data) {
                    result(data);
                });
            }
        }
    });

    var Put = Class.create({
        initialize: function (offer) {
            if (offer) {
                mongoDB.insertDocuments('vozime_db', 'drivers', offer);
            }
        }
    });

    return {
        Put : Put,
        Get : Get
    }
})();